﻿<script runat="server" language="C#">
	protected void Page_Load(Object sender, EventArgs e) {
		// Set the page's content type.	
		Page.Response.ContentType = "text/javascript";
		// Clear all response headers.
		Page.Response.Clear();
		// Buffer response so that page is sent after processing is complete.
		Response.BufferOutput = true;
		// Write data to the page.
		Page.Response.Write(getData());
		// Send the output to the client.
		Page.Response.Flush();
		// Check whether the browser remains connected to the server.
		if(!Page.Response.IsClientConnected) {
			// If connected, then do something here.
		} else {
			// If the browser is not connected stop all response processing.
			Page.Response.End();
		}
	}
	/// <summary>Get data from database for Page.Response.Write.</summary>
    protected String getData() {	
		// Get records from database.
		ent.TableContents t2 = new ent.TableContents();
		System.Data.DataTable dt1 = t2.getContentsByType(ent.TableLists.enumContentType.Template);
		System.Text.StringBuilder sb1 = new System.Text.StringBuilder();

		sb1.Append("var tinyMCETemplateList = [");
		foreach(System.Data.DataRow dr1 in dt1.Rows) {
			int qsIdContentType = (int)dr1[ent.TableContents.TBL__contents__content_type];

			// Get style from row. If data is not style type, then return an empty string.
			switch(qsIdContentType) {
				case (int)ent.TableLists.enumContentType.Template:
					String name = (String)dr1[ent.TableContents.TBL__contents__content_title];
					String url = ResolveClientUrl("~/main/content_raw.aspx?id=" + dr1[ent.TableContents.TBL__contents__content_id].ToString());
					String description = (String)dr1[ent.TableContents.TBL__contents__content_header];
					sb1.AppendFormat("[\"{0}\", \"{1}\", \"{2}\"],", name, url, description);
					break;
				default:
					break;
			}
		}
		sb1.Remove(sb1.Length - 1, 1); // Remove last delimit.
		sb1.Append("];");	
		return sb1.ToString();	
	}
</script>